package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.Announcement;
import com.tanhua.dubbo.api.MessagesApi;
import com.tanhua.dubbo.mapper.AnnouncementsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class MessagesApiImpl implements MessagesApi {

    @Autowired
    private AnnouncementsMapper announcementsMapper;

    @Override
    public IPage<Announcement> findAnnouncements(Integer page, Integer pagesize) {
        IPage<Announcement> params = new Page<Announcement>(page,pagesize);
        QueryWrapper<Announcement> query = new QueryWrapper<>();
        query.orderByDesc("updated");//原来是by id
        return announcementsMapper.selectPage(params,query);
    }

    @Override
    public void updateById(Announcement announcement) {
        QueryWrapper<Announcement> query = new QueryWrapper<>();
        query.eq("id", announcement.getId());
        announcementsMapper.update(announcement,query);
    }

    @Override
    public void save(Announcement announcement) {
        announcementsMapper.insert(announcement);
    }

    @Override
    public void delete(Long id) {
        announcementsMapper.deleteById(id);
    }

}
